<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function find2smallet(arr) {
            let first = Number.MAX_VALUE;
            let second;
            for (let i = 0; i < arr.length; i++) {
                if (arr[i] < first) {
                    second = first;
                    first = arr[i];
                }
                if (arr[i] > first && arr[i] < second) {
                    second = arr[i];
                }
            }
            console.log(first);
            console.log(second);
        }
        const arr = [-1, 3, 4, 5, 3, 1, -5, 231, 312];
        find2smallet(arr);
    </script>
</body>

</html>